package jmine.tec.web.servlet.delegate;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;

import javax.servlet.ServletOutputStream;
import javax.servlet.ServletResponse;

/**
 * Provides a convenient implementation of the ServletResponse interface that can be subclassed by developers wishing to adapt the response
 * from a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped response
 * object.
 * 
 * @since Servlet 2.3
 * @see javax.servlet.ServletResponse
 * @version $Rev: 46019 $ $Date: 2004-09-14 04:56:06 -0500 (Tue, 14 Sep 2004) $
 */
public class ServletResponseWrapper implements ServletResponse {
    private final ServletResponse response;

    /**
     * Creates a ServletResponse adaptor wrapping the given response object.
     * 
     * @param response the response delegate
     */
    public ServletResponseWrapper(ServletResponse response) {
        if (response == null) {
            throw new IllegalArgumentException("Response cannot be null");
        }
        this.response = response;
    }

    /**
     * @return the delegating response
     */
    public ServletResponse getResponse() {
        return this.response;
    }

    /**
     * {@inheritDoc}
     */
    public void setCharacterEncoding(String charset) {
        this.response.setCharacterEncoding(charset);
    }

    /**
     * {@inheritDoc}
     */
    public String getCharacterEncoding() {
        return this.response.getCharacterEncoding();
    }

    /**
     * {@inheritDoc}
     */
    public ServletOutputStream getOutputStream() throws IOException {
        return this.response.getOutputStream();
    }

    /**
     * {@inheritDoc}
     */
    public PrintWriter getWriter() throws IOException {
        return this.response.getWriter();
    }

    /**
     * {@inheritDoc}
     */
    public void setContentLength(int len) {
        this.response.setContentLength(len);
    }

    /**
     * {@inheritDoc}
     */
    public void setContentType(String type) {
        this.response.setContentType(type);
    }

    /**
     * {@inheritDoc}
     */
    public String getContentType() {
        return this.response.getContentType();
    }

    /**
     * {@inheritDoc}
     */
    public void setBufferSize(int size) {
        this.response.setBufferSize(size);
    }

    /**
     * {@inheritDoc}
     */
    public int getBufferSize() {
        return this.response.getBufferSize();
    }

    /**
     * {@inheritDoc}
     */
    public void flushBuffer() throws IOException {
        this.response.flushBuffer();
    }

    /**
     * {@inheritDoc}
     */
    public boolean isCommitted() {
        return this.response.isCommitted();
    }

    /**
     * The default behavior of this method is to call reset() on the wrapped response object.
     */
    public void reset() {
        this.response.reset();
    }

    /**
     * The default behavior of this method is to call resetBuffer() on the wrapped response object.
     */
    public void resetBuffer() {
        this.response.resetBuffer();
    }

    /**
     * {@inheritDoc}
     */
    public void setLocale(Locale loc) {
        this.response.setLocale(loc);
    }

    /**
     * {@inheritDoc}
     */
    public Locale getLocale() {
        return this.response.getLocale();
    }
}
